//
//  Person.m
//  02_ClassAndObject
//
//  Created by dllo on 16/7/5.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Person.h"

@implementation Person

+ (instancetype)personWithName:(NSString *)name
                           age:(NSInteger)age {
    return [[[Person alloc] initWithName:name age:age]autorelease];
}

// 命名规范
- (instancetype)initWithName:(NSString *)name
                         age:(NSInteger)age {
    self = [super init];
    if (self) {
        _name = name;
        _age = age;
    }
    return self;
}

- (instancetype)initWithName:(NSString *)name {
    return [self initWithName:name age:0];
}

- (instancetype)initWithAge:(NSInteger)age {
    return [self initWithName:nil age:age];
}

- (void)sleep:(NSInteger) time {
    // NSLog是C语言函数
    NSLog(@"这个人睡了%ld年", time);
}

- (void)setName:(NSString *)name{
    if (_name != name) {
        [_name release];
        _name = [name retain];
    }
}

- (NSString *)name {
    return [[_name retain]autorelease];
}

@end
